<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Order_model extends CI_Model { 


		
	function insert($data1) {
	
		$this->db->insert('order',$data1);
		$insert_id = $this->db->insert_id();
		return $insert_id;
	}
	
	function insert_order($data2) {
		
		$this->db->insert('order_mdc',$data2);
	}
	
	function select_order_mdc($order_id) {
	
		$this->db->select('*');
		$this->db->from('order_mdc');
		$this->db->where('order_id',$order_id);
		$this->db->join('inventories','order_mdc.mdc_id = inventories.mdc_id');
		$this->db->join('mdctype','inventories.mdctype_id = mdctype.mdctype_id');
		$qurey = $this->db->get();
		return $qurey->result_array();
		
	}
	
	function delete_mdc($id)
	{
		$this->db->where('mdc_id', $id);
		$this->db->delete('inventories');
	}
	
	function select_mdc($id_mdc)
	{
		$this->db->select('*');
		$this->db->from('inventories');
		$this->db->where('mdc_id',$id_mdc);
		$qurey = $this->db->get();
		return $qurey->row_array();
	}
	
	function select_amount($id) {
	
		$this->db->select('total');
		$this->db->from('order');
		$this->db->where('order.order_id',$id);
		$qurey = $this->db->get();
		return $qurey->row_array();
	}
	
	
	function update_total($id,$total) {
	
		$this->db->where('order_id',$id);
		$this->db->update('order',$total);
	}
	
	function select_total($order_id)
	{
		$this->db->select('total');
		$this->db->from('order');
		$this->db->where('order_id',$order_id);
		$qurey = $this->db->get();
		return $qurey->row_array();
	}
	
	function update_confirm_order($order_id,$data)
	{
		$this->db->where('order_id',$order_id);
		$this->db->update('order',$data);
	}
	
	function delete_mdc_order($mdc_id,$order_id)
	{
		$this->db->where('mdc_id', $mdc_id);
		$this->db->where('order_id', $order_id);
		$this->db->delete('order_mdc');
	}
	function delete_order($order_id)
	{
		
		$this->db->where('order_id', $order_id);
		$this->db->delete('order');
	}
	function select_mdc_mdc_id($order_id,$mdc_id)
	{
		$this->db->select('*');
		$this->db->from('order_mdc');
		$this->db->where('order_id',$order_id);
		$this->db->where('mdc_id',$mdc_id);
		$qurey = $this->db->get();
		return $qurey->row_array();
	}
	 function update_totalsum($order_id,$data) {
	
		$this->db->where('order_id',$order_id);
		$this->db->update('order',$data);
	}
}
